package com.example.cadmin.controller;

import com.example.cadmin.utils.ChangeCharset;
import com.example.cadmin.utils.ResponseModel;
import io.netty.buffer.Unpooled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestTcpSendController {
    @Resource
    ChangeCharset changeCharset;

    @GetMapping("/clientList")
    public ResponseModel clientList() {
//        System.out.println(NettyServerHandler.channelGroup);
//        NettyServerHandler.channelGroup.forEach(channel -> {
//            System.out.println("客户ip及PORT" + channel.remoteAddress());
//        });
        return ResponseModel.success();
    }

    @GetMapping("/sengClient")
    public ResponseModel sengClient(@RequestParam(value = "clientIp") String clientIp) {
//        NettyServerHandler.channelGroup.forEach(channel -> {
//            if (clientIp.equals(channel.remoteAddress().toString())) {
//                try {
//                    channel.writeAndFlush(Unpooled.buffer().writeBytes(("SHOWPARA:" + "\r\n").getBytes()));
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//                System.out.println("已发送");
//            } else {
//                System.out.println("未发送");
//            }
//        });

        return ResponseModel.success();
    }
}
